﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnalyseCrmMana;

namespace AnalyseCRM.InteractiveData
{
    public partial class AuthorityManagementAjax : System.Web.UI.Page
    {
        private string _paramValue = "", _paramType = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["paramvalue"] != null)
            {
                _paramValue = Server.UrlDecode(Request["paramvalue"].ToString());
            }
            if (Request["paramtype"] != null)
            {
                _paramType = Request["paramtype"].ToString();
            }
            Response.Write(buildHtml(_paramValue, _paramType));
        }

        public StringBuilder buildHtml(string prparamValue, string prparamType)
        {
            StringBuilder returnValue = null;
            AuthorityMana authmana = null;
            switch (prparamType)
            {
                #region 新增权限
                case "insertnewauthority":
                    returnValue = new StringBuilder();
                    string[] accpara = prparamValue.Split('|');
                    authmana = new AuthorityMana();
                    authmana.authorityno = 0;
                    authmana.authorityname = accpara[0];
                    authmana.url = accpara[1];
                    authmana.nodeid = 0;
                    authmana.pnodeid = 0;
                    if (authmana.AndNewAuthority(authmana) > 0)
                    {
                        returnValue.Append("SUCCESS");
                    }
                    else
                    {
                        returnValue.Append("ERROR");
                    }
                    break;
                #endregion
                #region 获取所有权限
                case "getAllauthoritys":
                    returnValue = new StringBuilder();
                    authmana = new AuthorityMana();
                    IList<AuthorityMana> authlist = authmana.getAllauthoritys();
                    int egcount = authmana.getAllauthoritysCount();
                    if (authlist != null && authlist.Count > 0)
                    {
                        returnValue.Append(JsonHelper.ListToJson(authlist));
                        returnValue.Append("$" + egcount);
                    }
                    else
                    {
                        returnValue.Append("none$0");
                    }
                    break;
                #endregion

                #region 删除权限
                case "deleteauthority":
                    returnValue = new StringBuilder();                    
                    authmana = new AuthorityMana();
                    int authno = Convert.ToInt32(prparamValue);
                    if (authmana.DeleteAuthority(authno) > 0)
                    {
                        returnValue.Append("SUCCESS");
                    }
                    else
                    {
                        returnValue.Append("ERROR");
                    }
                    break;
                #endregion
                default:
                    break;
            }
            return returnValue;

        }  
    
    }
}